//
//  UserViewController.m
//  舒适家
//
//  Created by dllo on 15/9/28.
//  Copyright (c) 2015年 lsc. All rights reserved.
//

#import "UserViewController.h"
#import "CollectingViewController.h"
#import "GuanyuViewController.h"
@interface UserViewController ()

@end

@implementation UserViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title=@"我";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20],NSForegroundColorAttributeName:[UIColor blackColor]}];
    self.AllArray=[NSMutableArray arrayWithObjects:@"我的收藏",@"清除缓存",@"LeftFrnder", nil];

    UIView *aView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200*HEIGHTSCALE)];
    aView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"liangyanqiha.png"]];

    self.myTableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    self.myTableView.dataSource=self;
    self.myTableView.delegate=self;
    [self.view addSubview:self.myTableView];
    self.myTableView.tableHeaderView=aView;
    
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.AllArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
     static NSString *identifier=@"reuse";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
//    if (indexPath.row==3) {
//        self.button=[UIButton buttonWithType:UIButtonTypeCustom];
//        self.button.frame=CGRectMake(cell.frame.size.width-10, cell.frame.origin.y, 60, 44);
//        [self.button setImage:[UIImage imageNamed:@"iconfont-guan.png"] forState:UIControlStateNormal];
//        [self.button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
//        
//        [cell addSubview:self.button];
//    }
    cell.textLabel.text=[self.AllArray objectAtIndex:indexPath.row];
    return cell;
}
//-(void)buttonAction
//{
//    NSString *str=[[NSUserDefaults standardUserDefaults]objectForKey:@"night"];
//    if ([str  isEqualToString:@"yes"])
//    {
//        [self.button setImage:[UIImage imageNamed:@"iconfont-guan.png"] forState:UIControlStateNormal];
//        [[NSNotificationCenter defaultCenter]postNotificationName:@"changeColor" object:@"no"];
//        
//    }else
//    {
//        [self.button setImage:[UIImage imageNamed:@"iconfont-kai.png"] forState:UIControlStateNormal];
//        [[NSNotificationCenter defaultCenter]postNotificationName:@"changeColor" object:@"yes"];
//    }
//
//}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.row==0) {
        CollectingViewController *collecVC=[[CollectingViewController alloc]init];
        collecVC.hidesBottomBarWhenPushed=YES;
        [self.navigationController pushViewController:collecVC animated:YES];
    }
    if (indexPath.row==1) {
        NSInteger size=[[SDImageCache sharedImageCache]getSize];
        float totalSize = size / 1024.0 / 1024.0;
        
        NSString *str=[NSString stringWithFormat:@"缓存大小:%.2fMB",totalSize];
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"缓存清除成功" message:str delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        //清除缓存
        [[SDImageCache sharedImageCache]clearDisk];
    }
    
    if (indexPath.row==2) {
        GuanyuViewController *guanyuVC=[[GuanyuViewController alloc]init];
        guanyuVC.hidesBottomBarWhenPushed=YES;
        [self.navigationController pushViewController:guanyuVC animated:YES];
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
